﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace AppMVVM.Models
{
    public class Article
    {
        public string Title { get; set; }
        public string Link { get; set; }
        public string SourceLink { get; set; }
        public string Description { get; set; }
        public DateTime? PublicationDate { get; set; }
        public bool HaveBeenRed { get; set; }
        public bool IsFavorite { get; set; }
        public string SourceName { get; set; }

        public Article() { }
        public Article(XElement item)
        {
          if (item.Element("title") != null)
          {
            Title = item.Element("title").Value;
            if (Title.Length > 120)
              Title = Title.Substring(0, 120) + "...";
          }
          if (item.Element("link") != null)
            Link = item.Element("link").Value;
          if (item.Element("description") != null)
            Description = item.Element("description").Value;
          if (item.Element("pubDate") != null)
            PublicationDate = new DateTime?(Convert.ToDateTime(item.Element("pubDate").Value));
        }
    }
}
